﻿<?php
	//图片格式
	header("Content-type:image/png");
	//画布大小-图像资源
    $code=imagecreatetruecolor(200,40);
     //绘制背景颜色-颜色资源
    $jpeg=imagecolorallocate($code,200,200,200);
    //定义背景
    imagefilledrectangle($code,0,0,200,80,$jpeg);
	//干扰点
	for($i=1;$i<500;$i++){
		$p=imagecolorallocate($code,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
		imagesetpixel($code,mt_rand(0,200),mt_rand(0,200),$p);
	}
	//线
	for($i=1;$i<20;$i++){
		$p=imagecolorallocate($code,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
		imagearc($code,mt_rand(0,200),mt_rand(0,200),mt_rand(0,200),mt_rand(0,200),mt_rand(0,360),mt_rand(0,360),$p);
	}
	$str='123456789qwertyuipasdfghjklzxcvbnmZXCVBNMASDFGHJKLPIUYTREWQ';
	for($i=1;$i<=4;$i++){
	$j=mt_rand(0,strlen($str)-1);
	$font=$str[$j];
	$cod.=$font;
	$p=imagecolorallocate($code,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
	imagefttext($code,30,mt_rand(0,50),40*$i,40,$p,'C:/Windows/Fonts/simsun.ttc',$font);
	}

	
	$_SESSION['code']=$cod;

    //生成图像
    ob_clean();
    imagejpeg($code);
    